package com.itheima.server.controller;

import com.itheima.domain.db.UserInfo;
import com.itheima.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

/**
 * @author 阿鹏
 * @date 2021/1/23 19:59
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public ResponseEntity sendVerifyCode(@RequestBody Map map) {
        String phone = (String) map.get("phone");
        return userService.sendVerifyCode(phone);
    }

    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map map) {
        String phone = (String) map.get("phone");
        String code = (String) map.get("verificationCode");
        return userService.loginVerification(phone, code);
    }

    @PostMapping("/loginReginfo")
    public ResponseEntity loginReginfo(@RequestBody UserInfo userInfo){
        return userService.loginReginfo(userInfo);
    }

    @PostMapping("/loginReginfo/head")
    public ResponseEntity uploadHead(MultipartFile headPhoto) throws IOException {
        return userService.uploadHead(headPhoto);
    }
}
